'''
@Author: your name
@Date: 2020-02-05 11:30:08
@LastEditTime : 2020-02-05 12:04:39
@LastEditors  : Please set LastEditors
@Description: In User Settings Edit
@FilePath: \pyqt5\demo_081_btnShortCut.py
'''
from PyQt5.Qt import *


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle('demo_081_btnShortCut')
        self.resize(500,500)
        self.setup_ui()

    def setup_ui(self):
        self.btnShortCut()

    def btnShortCut(self):
        # ---------------QLabel快捷键-------------------begin--
        # 使用ALT+N作为快捷键
        nameLb1 = QLabel('&Name',self)
        nameEd1 = QLineEdit(self)
        nameLb1.setBuddy(nameEd1)

        nameLb2 = QLabel('&Password',self)
        nameEd2 = QLineEdit(self)
        nameLb2.setBuddy(nameEd2)

        btnOk = QPushButton('&Ok',self)
        btnCancel = QPushButton('&Cancel',self)

        mainLayout = QGridLayout()
        mainLayout.addWidget(nameLb1,0,0)
        mainLayout.addWidget(nameEd1,0,1,1,2)

        mainLayout.addWidget(nameLb2,1,0)
        mainLayout.addWidget(nameEd2,1,1,1,2)
        mainLayout.addWidget(btnOk,2,1)
        mainLayout.addWidget(btnCancel,2,2)

        self.setLayout(mainLayout)
        # ---------------QLabel快捷键-------------------end----

        btn = QPushButton('&Lbc',self)
        #btn.clicked.connect(lambda : print('btn is clicked'))
        btn.pressed.connect(lambda : print('btn is pressed'))

        btn.setAutoRepeat(True)
        btn.setAutoRepeatDelay(2000)
        btn.setAutoRepeatInterval(1000)
        # shortcut is not useful!?? 
        # is occupied by others
        #btn.setText('&Abc')
        #btn.setShortcut('Alt+a')


if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)

    win = Window()
    win.show()
    sys.exit(app.exec_())
